/*
 * @(#)XfvhdlError.java        3.0                            2004/09/14
 *
 * This file is part of Xfuzzy 3.0, a design environment for fuzzy logic
 * based systems.
 *
 * (c) 2000 IMSE-CNM. The authors may be contacted by the email address:
 *                    xfuzzy-team@imse.cnm.es
 *
 * Xfuzzy is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation.
 *
 * Xfuzzy is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

package xfuzzy.xfvhdl;

/**
* Clase que gestiona los errores que se producen el el proceso de 
* s�ntesis.
* @author Jos� Mar�a �vila Maireles, <b>e-mail</b>: josavimai@alum.us.es
* @version 3.0
*/
public final class XfvhdlError {

   //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
   //		  ATRIBUTOS PRIVADOS DE LA CLASE 				        
   //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
   private static String messages = new String();
   private String mensaje;
   private int cod;
   private static int errors = 0;
   private static int warnings = 0;
   private XfvhdlMessage msg = new XfvhdlMessage(Xfvhdl.xfuzzy);

   //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
   //				CONSTRUCTORES DE LA CLASE					   
   //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//

   /**
   * Constructor de la clase XFvhdlError.
   * @param c C�digo del error producido.
   */
   public XfvhdlError(int c) {
      error(c);
      messages += "\nERROR " + cod + ": " + mensaje;
      errors++;
   }

   /**
   * Constructor de la clase XFvhdlError.
   * @param c C�digo del error producido.
   * @param s Cadena a mostrar despu�s del error.
   */
   public XfvhdlError(int c, String s) {
      error(c);
      messages += "\nERROR " + cod + ": " + mensaje + " " + s;
      errors++;
   }

   /**
   * Constructor por defecto de la clase XFvhdlError.
   */
   public XfvhdlError() {
   }

   //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
   //				  M�TO_DOS P�BLICOS DE LA CLASE				   
   //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//

   /**
   * M�todo para generar un warning.
   * @param c C�digo del warning producido.
   	*/
   public void newWarning(int c) {
      error(c);
      messages += "\nWARNING " + cod + ": " + mensaje;
      warnings++;
   }

   /**
   * M�todo que indica si existe algun error.
   */
   public boolean hasErrors() {
      boolean e = false;
      if (errors > 0)
         e = true;

      return e;
   }

   /**
   * M�todo que resetea los errores y los warnings.
   */
   public void resetAll() {
      messages = "";
      errors = 0;
      warnings = 0;
   }

   /**
   	* M�todo para generar un warning.
   	* @param c C�digo del warning producido.
   	* @param s Cadena a mostrar despu�s del warning.
   	*/
   public void newWarning(int c, String s) {
      error(c);
      messages += "\nWARNING " + cod + ": " + mensaje + " " + s;
      warnings++;
   }

   /**
   * M�todo que muestra por pantalla o en el log todos los errores 
   * acumulados.
   */
   public void show() {
      String cad1 =
         new String(
            "\n\n------------------------------------"
               + "-------------\n\n    Finished with 0 errors "
               + "and 0 warnings.\n");
      String cad2 =
         new String(
            "\n\n--------------------------------------------"
               + "-----\n\n    Finished with "
               + errors
               + " errors and "
               + warnings
               + " warnings.\n"
               + messages
               + "\n");
      if (errors == 0 && warnings == 0)
         msg.addMessage(cad1);
      else
         msg.addMessage(cad2);

      msg.show();
   }

   //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
   //			M�TO_DOS PRIVADOS DE LA CLASE				        
   //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//

   /**
   * M�todo privado que genera la cadena de identificaci�n del error 
   * o del warning.
   * @param c C�digo del error o warning producido 
   */
   private void error(int c) {
      if (c == 1) {
         cod = c;
         mensaje = new String("Parser error");
      } else if (c == 2) {
         cod = c;
         mensaje = new String("Can't create output directory");
      } else if (c == 3) {
         cod = c;
         mensaje =
            new String(
               "All input linguistic variables must have the "
                  + "same number of membership functions for VHDL "
                  + "synthesis");
      } else if (c == 4) {
         cod = c;
         mensaje =
            new String(
               "The maximum overlapping degree must be two "
                  + "in variable");
      } else if (c == 5) {
         cod = c;
         mensaje =
            new String("There isn't any membership function in variable");
      } else if (c == 6) {
         cod = c;
         mensaje = new String("Bad call, usage:\n\n");
         mensaje += "For grafical mode use: \n"
            + "\t\txfvhdl -g\n"
            + "\nFor console mode use:\n"
            + "\t\txfvhdl <XFL3-file> [-o <prefix>] [-n <number>] "
            + "[-d <number>] [-p <number>]\n"
            + "\t\t\t\t[-k <number>] [-L <directory>] [-Cf [-withnull]] "
            + "[-S] [-I] [-C<x|e|c>]\n"
            + "\t\t\t\t[-E<l|h>] [-O<a|s>] [-M<b|d|o|l>] [-Dv <device>] "
            + "[-T <family>] [-inROM]\n\n"
            + "\t\t<XFL-file> : Source XFL 3 file.\n\n"
            + "\t\t-o <prefix> : Use <prefix> for output files.\n"
            + "\t\t\t\tBy default, .\\"
            + XfvhdlProperties.OUTPUT_DIRECTORY_DEFAULT
            + "\\"
            + XfvhdlProperties.OUTPUT_FILE_DEFAULT
            + " is used\n"
            + "\t\t-n <number> : Use <number> bits for inputs and "
            + "output.\n"
            + "\t\t\t\tBy default, "
            + XfvhdlProperties.N_DEFAULT
            + " bits are used\n"
            + "\t\t-d <number> : Use <number> bits for membership "
            + "degree.\n"
            + "\t\t\t\tBy default, "
            + XfvhdlProperties.grad_DEFAULT
            + " bits are used\n"
            + "\t\t-p <number> : Use <number> bits for function slopes "
            + "(implies arithmetic\n"
            + "\t\t\t\tcalculation of antecedents). p must be >= d.\n"
            + "\t\t\t\tBy default, it is not used\n"
            + "\t\t-k <number> : Use <number> bits for the second "
            + "defuzzification parameter.\n"
            + "\t\t\t\tBy default, "
            + XfvhdlProperties.K_DEFAULT
            + " bits are used\n"
            + "\t\t-L <directory> : Defines <directory> as the "
            + "components library directory.\n"
            + "\t\t\t\tBy default, .\\"
            + XfvhdlProperties.LIBRARY_DIRECTORY_DEFAULT
            + " is used\n"
            + "\t\t-Cf : Generate complementary files with memory "
            + "contents\n"
            + "\t\t\t-withnull : Generate <prefix>rulesmem.dat with "
            + "null's rows. (Only with -Cf before)\n"
            + "\t\t-S : Execute the synthesis tool once the VHDL code "
            + "has been generated\n"
            + "\t\t-I : Execute the Xilinx implementation tools\n"
            + "\t\t-C : Select synthesis tool:\n"
            + "\t\t\t\tx : Xilinx XST (This is the default)\n"
            + "\t\t\t\te : Synopsys FPGA Express\n"
            + "\t\t\t\tc : Synopsys FPGA Compiler 2\n"
            + "\t\t-E : Map effort to be used by the synthesis tool:\n"
            + "\t\t\t\tl : Low (This is the default)\n"
            + "\t\t\t\th : High\n"
            + "\t\t-O : Synthesis tool optimization:\n"
            + "\t\t\t\ta : area\n"
            + "\t\t\t\ts : speed\n"
            + "\t\t-M : Memory to be used:\n"
            + "\t\t\t\tb : RAM - Block\n"
            + "\t\t\t\td : RAM - Distributed\n"
            + "\t\t\t\to : ROM (default)\n"
            + "\t\t\t\tl : Combinatorial logic\n"
            + "\t\t-Dv <device> : Defines <device> as the target "
            + "FPGA device for the\n"
            + "\t\t\t\tsyntehsis tool. By default, "
            + XfvhdlProperties.PART_TYPE_DEFAULT
            + " is used\n"
            + "\t\t-T <family> : Defines <family> as the target FPGA "
            + "family for Synopsys\n"
            + "\t\t\t\tsyntehsis tool. By default, "
            + XfvhdlProperties.TARGET_DEFAULT
            + " is used\n"
            + "\t\t-inROM : Generate Rules Memory as ROM\n";
      } else if (c == 7) {
         cod = c;
         mensaje =
            new String(
               "Default value will be used because isn't "
                  + "complete the parameter");
      } else if (c == 8) {
         cod = c;
         mensaje = new String("Bad parameters");
      } else if (c == 9) {
         cod = c;
         mensaje = new String("Only one rulebase system allowed");
      } else if (c == 10) {
         cod = c;
         mensaje = new String("Only simple rules allowed. Error in rule ");
      } else if (c == 12) {
         cod = c;
         mensaje = new String("not used");
      } else if (c == 13) {
         cod = c;
         mensaje = new String("Without consequent in rule");
      } else if (c == 15) {
         cod = c;
         mensaje = new String("Isn't IS type the rule");
      } else if (c == 16) {
         cod = c;
         mensaje = new String("Bad variables in rule");
      } else if (c == 17) {
         cod = c;
         mensaje = new String("Undefined error in rule");
      } else if (c == 18) {
         cod = c;
         mensaje =
            new String("Bad -Mx paremeter. Will be used -Mo by default");
      } else if (c == 19) {
         cod = c;
         mensaje =
            new String(
               "Increase bitsize for inputs to obtain more "
                  + "precision.");
      } else if (c == 20) {
         cod = c;
         mensaje =
            new String(
               "No output directory valid. By default "
                  + XfvhdlProperties.OUTPUT_DIRECTORY_DEFAULT
                  + ".");
      } else if (c == 21) {
         cod = c;
         mensaje =
            new String(
               "No prefix file valid. By default "
                  + XfvhdlProperties.OUTPUT_FILE_DEFAULT
                  + ".");
      } else if (c == 22) {
         cod = c;
         mensaje =
            new String("Bad -Ex paremeter. Will be used -El by default");
      } else if (c == 23) {
         cod = c;
         mensaje =
            new String("Bad -C? paremeter. Will be used -Cx by default");
      } else if (c == 24) {
         cod = c;
         mensaje =
            new String(
               "There are errors, so can�t execute any synthesis "
                  + "tool");
      } else if (c == 25) {
         cod = c;
         mensaje = new String("Exception in external tool");
      } else if (c == 26) {
         cod = c;
         mensaje = new String("Synthesis tool not supported");
      } else if (c == 27) {
         cod = c;
         mensaje =
            new String(
               "There are errors, so can�t execute any "
                  + "implementation tool");
      } else if (c == 28) {
         cod = c;
         mensaje =
            new String(
               "AND operation not valid. Will be used Minimun "
                  + "by default");
      } else if (c == 29) {
         cod = c;
         mensaje =
            new String(
               "Defuzzification Method not implemented. Will "
                  + "be used FuzzyMean by default");
      } else if (c == 30) {
         cod = c;
         mensaje =
            new String("Not variable allowed to aritmetic calculus");
      } else if (c == 31) {
         cod = c;
         mensaje =
            new String("Families of Membership Functions not allowed");
      } else {
         cod = 0;
         mensaje = new String("UNDEFINED ERROR");
      }
   }

} // Fin de la clase.
